<template>
  <div class="detail-navbar">
    <Navbar>
      <div slot="left" class="left" @click="backClick">
        <img src="~assets/images/common/back.svg" alt="back" />
      </div>
      <div slot="center" class="center">
        <div
          v-for="(item, index) in titles"
          :key="index"
          :class="{ active: currentIndex === index }"
          @click="itemClick(index)"
        >
          {{ item }}
        </div>
      </div>
      <div class="rigth"></div>
    </Navbar>
  </div>
</template>

<script>
export default {
  data() {
    return {
      titles: ["商品", "参数", "评论", "推荐"],
      currentIndex: 0,
    };
  },
  methods: {
    // 详情页标题点击
    itemClick(index) {
      this.currentIndex = index;
      this.$emit("titleClick", index);
    },
    backClick() {
      // 因为详情页路由中多了#，所以go()的参数为-2
      this.$router.go(-2);
    },
  },
};
</script>

<style lang="less" scoped>
.detail-navbar {
  .left {
    img {
      margin-top: 12px;
    }
  }
  .center {
    display: flex;
    justify-content: space-evenly;
  }
  .active {
    color: var(--color-high-text);
  }
}
</style>